package com.zzptc.zzsgz.bdsjws.fragments;


import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import com.zzptc.zzsgz.bdsjws.Adapter.AddAdapter;
import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.AddContactsActivity;
import com.zzptc.zzsgz.bdsjws.fragments.base.BaseFragmentbase;
import com.zzptc.zzsgz.bdsjws.vo.AddTel;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;


public class SecondFragment extends BaseFragmentbase {
    AddAdapter addAdapter;
    String tel;
    @BindView(R.id.et_add_contacts)
    EditText etAddContacts;
    @BindView(R.id.img_add_contacts)
    ImageView imgAddContacts;
    @BindView(R.id.btn_add_contacts)
    Button btnAddContacts;
    @BindView(R.id.rv_add_contacts)
    RecyclerView rvAddContacts;

    List<AddTel> list = new ArrayList<AddTel>();

    @Override
    public int getXML() {
        return R.layout.second_fragment;

    }

    @Override
    public void initView() {
        etAddContacts.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                btnAddContacts.setVisibility(View.VISIBLE);
                imgAddContacts.setVisibility(View.GONE);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    @Override
    public void initDate() {

    }


    @OnClick(R.id.img_add_contacts)
    public void onViewClicked() {
        startActivity(new Intent(getActivity(), AddContactsActivity.class));

    }


    @OnClick(R.id.btn_add_contacts)
    public void onYesClicked() {
        tel = etAddContacts.getText().toString().trim();
        etAddContacts.setText("");
        btnAddContacts.setVisibility(View.GONE);
        imgAddContacts.setVisibility(View.VISIBLE);

        AddTel addTel = new AddTel();
        addTel.setTelephone(tel);
        list.add(addTel);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        rvAddContacts.setLayoutManager(linearLayoutManager);

        addAdapter = new AddAdapter(list);
        rvAddContacts.setAdapter(addAdapter);
    }


}
